/******************************************************************************/
/*                                                                            */
/*  Copyright (c) 2009: ngi-central.org                                       */
/*  All rights reserved.                                                      */
/*                                                                            */
/******************************************************************************/


#include <boost/test/unit_test.hpp>

#include "..\..\include\sgl\hyper_ellipsoid.h"

BOOST_AUTO_TEST_SUITE( ellipse2d )


BOOST_AUTO_TEST_CASE( ellipse2d__default_constructor )
{
	sgl::ellipse2 a;

	BOOST_CHECK( a.origin()[0] == 0 );
	BOOST_CHECK( a.origin()[1] == 0 );
	BOOST_CHECK( a.radius()[0] == 0 );
	BOOST_CHECK( a.radius()[1] == 0 );

	sgl::ellipse2 b(
		sgl::point<2>(1, 2),
		sgl::vector<2>(3, 4));

	BOOST_CHECK( b.origin()[0] == 1 );
	BOOST_CHECK( b.origin()[1] == 2 );
	BOOST_CHECK( b.radius()[0] == 3 );
	BOOST_CHECK( b.radius()[1] == 4 );
}

BOOST_AUTO_TEST_CASE( ellipse2d__copy_constructor )
{
	sgl::ellipse2 a(
		sgl::ellipse2(
			sgl::point<2>(1, 2),
			sgl::vector<2>(3, 4)));

	BOOST_CHECK( a.origin()[0] == 1 );
	BOOST_CHECK( a.origin()[1] == 2 );
	BOOST_CHECK( a.radius()[0] == 3 );
	BOOST_CHECK( a.radius()[1] == 4 );
}

BOOST_AUTO_TEST_CASE( ellipse2d__copy_assignment )
{
	sgl::ellipse2 a;
	a = sgl::ellipse2(
			sgl::point<2>(1, 2),
			sgl::vector<2>(3, 4));

	BOOST_CHECK( a.origin()[0] == 1 );
	BOOST_CHECK( a.origin()[1] == 2 );
	BOOST_CHECK( a.radius()[0] == 3 );
	BOOST_CHECK( a.radius()[1] == 4 );
}

BOOST_AUTO_TEST_CASE( ellipse2d__swap )
{
	sgl::ellipse2 a(sgl::ellipse2(
		sgl::point<2>(1, 2),
		sgl::vector<2>(3, 4)));
	sgl::ellipse2 b;

	a.swap(b);

	BOOST_CHECK( a.origin()[0] == 0 );
	BOOST_CHECK( a.origin()[1] == 0 );
	BOOST_CHECK( a.radius()[0] == 0 );
	BOOST_CHECK( a.radius()[1] == 0 );
	BOOST_CHECK( b.origin()[0] == 1 );
	BOOST_CHECK( b.origin()[1] == 2 );
	BOOST_CHECK( b.radius()[0] == 3 );
	BOOST_CHECK( b.radius()[1] == 4 );

	b.swap(a);

	BOOST_CHECK( a.origin()[0] == 1 );
	BOOST_CHECK( a.origin()[1] == 2 );
	BOOST_CHECK( a.radius()[0] == 3 );
	BOOST_CHECK( a.radius()[1] == 4 );
	BOOST_CHECK( b.origin()[0] == 0 );
	BOOST_CHECK( b.origin()[1] == 0 );
	BOOST_CHECK( b.radius()[0] == 0 );
	BOOST_CHECK( b.radius()[1] == 0 );
}

BOOST_AUTO_TEST_CASE( ellipse2d__origin )
{
	sgl::ellipse2 a;

	BOOST_CHECK( a.origin()[0] == 0 );
	BOOST_CHECK( a.origin()[1] == 0 );

	a.origin()[0] = 1;
	a.origin()[1] = 1;

	BOOST_CHECK( a.origin()[0] == 1 );
	BOOST_CHECK( a.origin()[1] == 1 );
}

BOOST_AUTO_TEST_CASE( ellipse2d__size )
{
	sgl::ellipse2 a;

	BOOST_CHECK( a.radius()[0] == 0 );
	BOOST_CHECK( a.radius()[1] == 0 );

	a.radius()[0] = 1;
	a.radius()[1] = 1;

	BOOST_CHECK( a.radius()[0] == 1 );
	BOOST_CHECK( a.radius()[1] == 1 );
}

BOOST_AUTO_TEST_CASE( ellipse2d__geometric_type )
{
	sgl::ellipse2 a;

	BOOST_CHECK( a.type() == sgl::geometric_primitive<>::hyper_ellipsoid );
}

BOOST_AUTO_TEST_CASE( ellipse2d__dimensions )
{
	sgl::ellipse2 a;

	BOOST_CHECK( a.dimensions() == 2 );
}

BOOST_AUTO_TEST_CASE( ellipse2d__operator_equality )
{
	sgl::ellipse2 a;
	sgl::ellipse2 b;

	BOOST_CHECK( a == b );

	sgl::ellipse2 c(sgl::point<2>(1, 2), sgl::vector<2>(3, 4));
	sgl::ellipse2 d(sgl::point<2>(1, 2), sgl::vector<2>(3, 4));

	BOOST_CHECK( c == d );
}

BOOST_AUTO_TEST_CASE( ellipse2d__operator_inequality )
{
	sgl::ellipse2 a;
	sgl::ellipse2 b(sgl::point<2>(1, 2), sgl::vector<2>(3, 4));

	BOOST_CHECK( a != b );
}

BOOST_AUTO_TEST_CASE( ellipse2d__addition )
{
	sgl::ellipse2 a;
	a += sgl::vector<2>(1, 2);

	BOOST_CHECK( a.origin()[0] == 1 );
	BOOST_CHECK( a.origin()[1] == 2 );
	BOOST_CHECK( a.radius()[0] == 0 );
	BOOST_CHECK( a.radius()[1] == 0 );

	sgl::ellipse2 b;
	sgl::vector<2> c(1, 2);
	sgl::ellipse2 d = b+c;

	BOOST_CHECK( d.origin()[0] == 1 );
	BOOST_CHECK( d.origin()[1] == 2 );
	BOOST_CHECK( d.radius()[0] == 0 );
	BOOST_CHECK( d.radius()[1] == 0 );

	sgl::ellipse2 e = c+b;

	BOOST_CHECK( e.origin()[0] == 1 );
	BOOST_CHECK( e.origin()[1] == 2 );
	BOOST_CHECK( e.radius()[0] == 0 );
	BOOST_CHECK( e.radius()[1] == 0 );
}

BOOST_AUTO_TEST_CASE( ellipse2d__subtraction )
{
	sgl::ellipse2 a;
	a -= sgl::vector<2>(1, 2);

	BOOST_CHECK( a.origin()[0] == -1 );
	BOOST_CHECK( a.origin()[1] == -2 );
	BOOST_CHECK( a.radius()[0] == 0 );
	BOOST_CHECK( a.radius()[1] == 0 );

	sgl::ellipse2 b;
	sgl::vector<2> c(1, 2);
	sgl::ellipse2 d = b-c;

	BOOST_CHECK( d.origin()[0] == -1 );
	BOOST_CHECK( d.origin()[1] == -2 );
	BOOST_CHECK( d.radius()[0] == 0 );
	BOOST_CHECK( d.radius()[1] == 0 );
}

BOOST_AUTO_TEST_CASE( ellipse2d__multiplication )
{
	sgl::ellipse2 a(
		sgl::point<2>(1, 2),
		sgl::vector<2>(3, 4));
	a *= 2;

	BOOST_CHECK( a.origin()[0] == 1 );
	BOOST_CHECK( a.origin()[1] == 2 );
	BOOST_CHECK( a.radius()[0] == 6 );
	BOOST_CHECK( a.radius()[1] == 8 );

	sgl::ellipse2 b(
		sgl::point<2>(1, 2),
		sgl::vector<2>(3, 4));
	sgl::ellipse2 d = b*3;

	BOOST_CHECK( d.origin()[0] == 1 );
	BOOST_CHECK( d.origin()[1] == 2 );
	BOOST_CHECK( d.radius()[0] == 9 );
	BOOST_CHECK( d.radius()[1] == 12 );

	sgl::ellipse2 e = 3*b;

	BOOST_CHECK( e.origin()[0] == 1 );
	BOOST_CHECK( e.origin()[1] == 2 );
	BOOST_CHECK( e.radius()[0] == 9 );
	BOOST_CHECK( e.radius()[1] == 12 );
}

BOOST_AUTO_TEST_CASE( ellipse2d__division )
{
	sgl::ellipse2 a(
		sgl::point<2>(1, 2),
		sgl::vector<2>(4, 6));
	a /= 2;

	BOOST_CHECK( a.origin()[0] == 1 );
	BOOST_CHECK( a.origin()[1] == 2 );
	BOOST_CHECK( a.radius()[0] == 2 );
	BOOST_CHECK( a.radius()[1] == 3 );

	sgl::ellipse2 b(
		sgl::point<2>(1, 2),
		sgl::vector<2>(4, 6));
	sgl::ellipse2 d = b/2;

	BOOST_CHECK( d.origin()[0] == 1 );
	BOOST_CHECK( d.origin()[1] == 2 );
	BOOST_CHECK( d.radius()[0] == 2 );
	BOOST_CHECK( d.radius()[1] == 3 );
}

BOOST_AUTO_TEST_SUITE_END()

